package com.steven.ourcontest.chat.helper

import com.steven.ourcontest.chat.bean.ApplyFriend
import com.steven.ourcontest.chat.bean.ChatReceiveMessage
import com.tencent.mmkv.MMKV

object MessageHelper {
    private val kv = MMKV.defaultMMKV()
    var currentChatUid = 0L

    val messageUnReadMap = HashMap<Long, ArrayList<ChatReceiveMessage>>()
    val applyUnReadMap = HashMap<Long, ApplyFriend>()

    fun onReceiveMessage(arrayList: ArrayList<ChatReceiveMessage>) {
        arrayList.forEach {
            if (it.sendUser != currentChatUid) {
                if (messageUnReadMap.containsKey(it.sendUser)) {
                    val list = messageUnReadMap[it.sendUser]
                    list?.add(it)
                } else {
                    val list = ArrayList<ChatReceiveMessage>()
                    list.add(it)
                    messageUnReadMap[it.sendUser] = list
                }
            }
        }
    }

    fun onReceiveApply(arrayList: ArrayList<ApplyFriend>) {
        arrayList.forEach {
            applyUnReadMap[it.applicantUser] = it
        }
    }
}